package besteAukera;

import java.awt.Color;
import java.awt.Graphics;
import java.io.Serializable;

public class SarreraDatu  implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Integer balioa;
	private int x;
	private int y;
	@SuppressWarnings("unused")
	private Integer lot;
	private boolean lotura;
	public int bitKopurua;
	private String datuMota;
	public SarreraDatu(int x1, int y1, Integer bal) {
lotura=false;
		lot = null;
		x = x1;
		y = y1;
		balioa = bal;
		
	}
public void inkrementatuBalioa(){
	if ((datuMota.compareTo("Positiboa")==0)||(bitKopurua==1)){
	if (balioa>(Math.pow(2, bitKopurua))-2)
		balioa=0;
	else
	balioa=balioa+1;
	}
	else if (datuMota.compareTo("BirakoOs")==0){
		
		if (balioa>(Math.pow(2, bitKopurua-1))-2)
			balioa=-((Double)Math.pow(2, bitKopurua-1)).intValue();
		else
		balioa=balioa+1;
		}
	
}
public void setBitKopurua(int kopurua){
	bitKopurua=kopurua;
}
public void setDatuMota(String datMot){
	datuMota=datMot;
}
public int getBitKopurua(){
	return bitKopurua;
}
	public void marraztu(Graphics g) {
		float[] letra = Color.RGBtoHSB(238, 238, 238, null);
		g.setColor(Color.getHSBColor(letra[0], letra[1], letra[2]));
		g.setColor(Color.blue);		
			if(balioa.toString().length()==2)
			g.drawString(balioa.toString(), x-6, y + 20);
			else if(balioa.toString().length()==3)
				g.drawString(balioa.toString(), x-12, y + 20);
			else 	g.drawString(balioa.toString(), x, y + 20);
	}

	public void ezabatu(Graphics g) {
		g.clearRect(x, y + 10, 5, 5);
	}

	public Integer getBalioa() {
		return balioa;
	}

	public void setBalioa(Integer bal) {
		balioa = bal;

	}

	public void setLotura(Integer l) {
		this.lot = l;
		lotura = true;
	}

	public boolean loturaDu() {
		return lotura;
	}

	public void setPosizioa(int x, int y) {
		this.x = x;
		this.y = y;
	}

	public int getX() {
		return x;
	}

	public int getY() {
		return y;
	}

	public boolean barruanDago(int x, int y) {
		if ((x > this.x) && (x < (this.x + 20)) && (y > this.y)
				&& (y + 10 < (this.y + 20))) {
			return true;
		}
		return false;
	}

	public void sarreraLotu(Integer id) {
		lot = id;
	}

	public void loturaEzabatu() {
		lot = null;
		lotura = false;
	}

}